home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / Programming / MSTPChart / Elements.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-26  |  4.4 KB  |  148 lines  |  [TEXT/KAHL]

  1. #include    "MST_Defines.h"
  2. #include    "MST_Externs.h"
  3. #include    "MST_Prototypes.h"
  4.  
  5.  
  6. /*_____________________________________________________________________________
  7.                         Close_Elements()- close our element window
  8. _____________________________________________________________________________*/
  9.  
  10.  
  11. void    Close_Elements    ()
  12. {
  13. /*
  14. •        See comments for Close_AboutMST() in the file About.c
  15. */
  16.     if    (ElementsDlog==NIL)    return;
  17.     DisposDialog    (ElementsDlog);
  18.     ElementsDlog    =    NIL;
  19. }
  20.  
  21.  
  22. /*_____________________________________________________________________________
  23.                         Open_Elements()- create and display our element window
  24. _____________________________________________________________________________*/
  25.  
  26.  
  27. void    Open_Elements    (int thisElement)
  28. {
  29.     GDHandle        saveDevice;
  30.     CGrafPtr        saveCGrafPtr;
  31.     Str255            thisString,    thatString;
  32.     
  33.     if    (thisElement<=0)                return;    /*Just in case an invalid element*/
  34.     if    (thisElement>Max_NumElements)    return;    /*snuck past us*/
  35. /*
  36. •        First, we may already have an element window open. We could allow many
  37. •        to be open at once, but our program allows only one at a time. One
  38. •        possibility is to simply reset the title of any existing element
  39. •        window to the new element, along with any other data associated with
  40. •        that window (for instance, if we had a variety of data about the
  41. •        element to display in the element window). Here, we simply choose to
  42. •        destroy the old window and create a new one.
  43. */
  44.  
  45.     if    (ElementsDlog!=NIL)                {    Close_Elements    ();    }
  46. /*
  47. •        See comments for Open_AboutMST() in the file About.c.
  48. */
  49.  
  50.     ElementsDlog = GetNewDialog    (ResID_Elements, NIL, (WindowPtr)-1);
  51. /*
  52. •        Now we have a little more work to do. Unlike our Periodic Chart window,
  53. •        our element window can have any one of many titles. So first we switch
  54. •        to the proper port,
  55. */
  56.     GetGWorld        (&saveCGrafPtr,&saveDevice);
  57.     SetGWorld        ((CGrafPtr)ElementsDlog,saveDevice);
  58. /*
  59. •        get the full name of the element, or generate the text equivalent of
  60. •        its atomic number if there is no name,
  61. */
  62.     if            (thisElement>=1&&thisElement<=110)    GetIndString    (thisString,ChemNamesStr,thisElement);
  63.     else if        (thisElement>=111)
  64.     {
  65.         strcpy        (&thisString,"Element ");
  66.         NumToString    (thisElement,&thatString);
  67.         p2cstr        (&thatString);
  68.         strcat        (&thisString,&thatString);
  69.         c2pstr        (&thisString);
  70.     }
  71. /*
  72. •        And set the window title to the name of the element.
  73. */
  74.     SetWTitle        (ElementsDlog,&thisString);
  75. /*
  76. •        Finally, we make the window visible. We have deliberately set the dialog
  77. •        template to be initially invisible, so that the process of inserting the
  78. •        element name into the window title is not visible to the user.
  79. */
  80.     ShowWindow        (ElementsDlog);
  81. /*
  82. •        Note that Listing2 in the original article had a call to
  83. •        SelectWindow(ElementsDlog) at this point. While the call did
  84. •        no harm, it was extraneous. Using -1 as the third parameter to
  85. •        GetNewDialog() makes it the active (frontmost) window.
  86. */
  87. }
  88.  
  89.  
  90. /*_____________________________________________________________________________
  91.                         UpDate_Elements()- update our element window
  92. _____________________________________________________________________________*/
  93.  
  94.  
  95. void    UpDate_Elements()
  96. {
  97.     GDHandle    saveDevice;
  98.     CGrafPtr    saveCGrafPtr;
  99.     int            loop1;
  100. /*
  101. •        Generally, see the comments to the update routine for the Periodic Chart
  102. •        window in the file Periodic.c. The element window update routine is the
  103. •        simplest of all...we are just drawing a dotted rectangle.
  104. */
  105.     if    (ElementsDlog==NIL)    return;
  106.     
  107.     GetGWorld    (&saveCGrafPtr,&saveDevice);
  108.     SetGWorld    ((CGrafPtr)ElementsDlog,saveDevice);
  109.     
  110.     BeginUpdate    (ElementsDlog);
  111.     
  112.     for    (loop1=13;loop1<=ElementsDlog->portRect.right-13;loop1+=2)
  113.     {
  114.         MoveTo    (loop1,ElementsDlog->portRect.top+13);
  115.         Line    (0,0);
  116.         
  117.         MoveTo    (loop1,ElementsDlog->portRect.bottom-13);
  118.         Line    (0,0);
  119.     }
  120.     for    (loop1=13;loop1<=ElementsDlog->portRect.bottom-13;loop1+=2)
  121.     {
  122.         MoveTo    (ElementsDlog->portRect.left+13,    loop1);
  123.         Line    (0,0);
  124.         
  125.         MoveTo    (ElementsDlog->portRect.right-13,    loop1);
  126.         Line    (0,0);
  127.     }
  128.     EndUpdate    (ElementsDlog);
  129.     SetGWorld    (saveCGrafPtr,saveDevice);
  130. }
  131.  
  132.  
  133. /*_____________________________________________________________________________
  134.                         Do_Elements()- handle events directed to our element window
  135. _____________________________________________________________________________*/
  136.  
  137.  
  138. void    Do_Elements    (EventRecord *thisEvent)
  139. /*
  140. •        This is just a stub of a function to demonstrate where
  141. •        you could add code to handle mouseclicks, keydowns, or other
  142. •        events directed to the element window.
  143. */
  144.  
  145. {
  146. }
  147.  
  148.